package cn.edu.scau.cmi.houzhicong.whole;

import cn.edu.scau.cmi.houzhicong.adapterPattern.adapter.ClassAdapter;
import cn.edu.scau.cmi.houzhicong.adapterPattern.adapter.ObjectAdapter;
import cn.edu.scau.cmi.houzhicong.adapterPattern.domain.AC220;
import cn.edu.scau.cmi.houzhicong.adapterPattern.domain.DC5;
import cn.edu.scau.cmi.houzhicong.interProgramming.domain.A;
import cn.edu.scau.cmi.houzhicong.interProgramming.domain.B;
import cn.edu.scau.cmi.houzhicong.interProgramming.domain.C;
import cn.edu.scau.cmi.houzhicong.singletonPattern.domain.MultiChairMan;
import cn.edu.scau.cmi.houzhicong.singletonPattern.domain.SingleChairMan;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import javafx.stage.Stage;

import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;



public class MainController implements Initializable {


    @FXML
    private ImageView imageView;


    @Override
    public void initialize(URL location, ResourceBundle resources) {
        imageView.setImage(new Image("/cn/edu/scau/cmi/houzhicong/whole/me.jpg", true));
    }


    public void exp01() {
        Text text = new Text();
        try {
            Pane vBox = new VBox();
            Button addButton = new Button("运行");

            addButton.setOnAction(e->{
                A a = null;
                a = new B();
                String s = "a = new B(), a said："+a.doSomething()+"\n";
                a = new C();
                s = s+"a = new C(), a said："+a.doSomething()+"\n";
                text.setText(s);
            });

            addButton.setPrefSize(100,30);
            vBox.getChildren().add(addButton);
            vBox.getChildren().add(text);

            Scene scene = new Scene(vBox,250,100);
            Stage stage = new Stage();
            stage.setScene(scene);
            stage.show();

        } catch(Exception e) {
            e.printStackTrace();
        }

    }


    private int accout = 1;
    public void exp02() {

        accout = 1;
        Text text = new Text("未输入ID");
        TextField textField = new TextField();

        try {
            Pane vBox = new VBox();
            Button addButton = new Button("获取主席");
            addButton.setOnAction(e->{
                SingleChairMan singleChairMan = SingleChairMan.getInstance(textField.getText());
                text.setText("共获取了"+accout++ +"次主席,其ID为"+ singleChairMan.getId());
            });

            textField.setPrefSize(100,30);
            addButton.setPrefSize(100,30);
            vBox.getChildren().add(textField);
            vBox.getChildren().add(addButton);
            vBox.getChildren().add(text);

            Scene scene = new Scene(vBox,250,100);
            Stage stage = new Stage();
            stage.setScene(scene);
            stage.show();
        } catch(Exception e) {
            e.printStackTrace();
        }
    }



    public void exp022() {
        accout = 1;
        Text text = new Text("未输入ID");
        TextField textField = new TextField();
        try {
            Pane vBox = new VBox();
            Button addButton = new Button("获取毛主席");
            addButton.setOnAction(e->{
                MultiChairMan multiChairMan = MultiChairMan.addMultiChairMan(textField.getText());
                if(multiChairMan!=null){
                    text.setText("共新建了"+accout++ +"次毛主席,其ID为"+ multiChairMan.getId());
                }else{
                    text.setText("新建次数已超过容纳量！");
                }

            });

            textField.setPrefSize(100,30);
            addButton.setPrefSize(100,30);
            vBox.getChildren().add(textField);
            vBox.getChildren().add(addButton);
            vBox.getChildren().add(text);

            Scene scene = new Scene(vBox,250,100);
            Stage stage = new Stage();
            stage.setScene(scene);
            stage.show();
        } catch(Exception e) {
            e.printStackTrace();
        }
    }

    public void exp03( ) throws Exception {
        Parent root = FXMLLoader.load(getClass().getResource("/cn/edu/scau/cmi/houzhicong/factoryPattern/gui/SimpleFactoryScene.fxml"));
        Stage stage = new Stage();
        stage.setTitle("简单工厂方法");
        stage.setScene(new Scene(root));
        stage.show();
    }

    public void exp04( ) throws Exception {
        Parent root = FXMLLoader.load(getClass().getResource("/cn/edu/scau/cmi/houzhicong/factoryPattern/gui/FactoryScene.fxml"));
        Stage stage = new Stage();
        stage.setTitle("工厂方法");
        stage.setScene(new Scene(root));
        stage.show();
    }

    public void exp05( ) throws Exception {
        Parent root = FXMLLoader.load(getClass().getResource("/cn/edu/scau/cmi/houzhicong/abstractFactoryPattern/gui/AbstractFactoryScene.fxml"));
        Stage stage = new Stage();
        stage.setTitle("抽象工厂方法");
        stage.setScene(new Scene(root));
        stage.show();
    }


    public void exp06() {
        Text text = new Text();
        try {

            Pane vBox = new VBox();
            Button addButton = new Button("运行");
            addButton.setOnAction(e->{
                DC5 dc5 = new ObjectAdapter(new AC220());
                text.setText("使用对象适配器，将220V电压转为："+dc5.output5V()+"V。");
            });

            addButton.setPrefSize(100,30);
            vBox.getChildren().add(addButton);
            vBox.getChildren().add(text);

            Scene scene = new Scene(vBox,250,100);
            Stage stage = new Stage();
            stage.setScene(scene);
            stage.show();

        } catch(Exception e) {
            e.printStackTrace();
        }
    }


    public void exp07() {
        Text text = new Text();
        try {

            Pane vBox = new VBox();
            Button addButton = new Button("运行");
            addButton.setOnAction(e->{
                DC5 dc5 = new ClassAdapter();
                text.setText("使用类适配器，将220V电压转为："+dc5.output5V()+"V。");
            });

            addButton.setPrefSize(100,30);
            vBox.getChildren().add(addButton);
            vBox.getChildren().add(text);

            Scene scene = new Scene(vBox,250,100);
            Stage stage = new Stage();
            stage.setScene(scene);
            stage.show();

        } catch(Exception e) {
            e.printStackTrace();
        }
    }

    public void exp08( ) throws Exception {
        Parent root = FXMLLoader.load(getClass().getResource("/cn/edu/scau/cmi/houzhicong/combinationPattern/gui/SafetyCombination.fxml"));
        Stage stage = new Stage();
        stage.setTitle("安全组合模式");
        stage.setScene(new Scene(root));
        stage.show();
    }

    public void exp09( ) throws Exception {
        Parent root = FXMLLoader.load(getClass().getResource("/cn/edu/scau/cmi/houzhicong/combinationPattern/gui/ConsistentCombination.fxml"));
        Stage stage = new Stage();
        stage.setTitle("一致性组合模式");
        stage.setScene(new Scene(root));
        stage.show();
    }

    public void exp10( ) throws Exception {
        Parent root = FXMLLoader.load(getClass().getResource(
                "/cn/edu/scau/cmi/houzhicong/hibernate/gui/Hibernate.fxml"));
        Stage stage = new Stage();
        stage.setTitle("Hibernate框架");
        stage.setScene(new Scene(root));
        stage.show();
    }









}

